﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO_HealthInsurance;
using BLL_HealthInsurance;
using DAO_HealthInsurance;
using System.Data;
namespace HealthInsuranceMgm.Admin
{
    public partial class UpdateEmpdetail : System.Web.UI.Page
    {
        DAOEmployee obj = new DAOEmployee();
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = obj.getinfoByUsername(Session["username"].ToString());
            int empno = Int32.Parse(dt.Rows[0]["EmpNo"].ToString());

            LoadData(empno);
        }
        public void message(string script)
        {

            Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", script, true);
        }

        public void LoadData(int empno)
        {
            DAOSecurityPassword secury = new DAOSecurityPassword();
            BLLEmployee obj = new BLLEmployee();
            DTOEmployee objDt = new DTOEmployee();
            objDt.EmpNo = empno;
            DataTable dt = obj.GetEmployeeById(objDt);
            HiddenField1.Value = dt.Rows[0]["EmpNo"].ToString();
         
           
           
            txtfirstname.Text = dt.Rows[0]["FirstName"].ToString();

            txtlastname.Text = dt.Rows[0]["LastName"].ToString();
            txtusername.Text = dt.Rows[0]["UserName"].ToString();
            txtpassword.Text =secury.DeCrypt( dt.Rows[0]["PassWord"].ToString());
            txtaddress.Text = dt.Rows[0]["Address"].ToString();

            txtcontact.Text = dt.Rows[0]["ContactNo"].ToString();
            txtstate.Text = dt.Rows[0]["State"].ToString();
            txtcountry.Text = dt.Rows[0]["Country"].ToString();
            txtcity.Text = dt.Rows[0]["City"].ToString();



        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            DAOSecurityPassword secu = new DAOSecurityPassword();
            int empNo = Int32.Parse(HiddenField1.Value.ToString());
            string firstName = txtfirstname.Text;
            string lastname = txtlastname.Text;
            string userName = txtusername.Text;
            string password =secu.EnCrypt( txtpassword.Text);
            string address = txtaddress.Text;
            string contactNo = txtcontact.Text;
            string state = txtstate.Text;
            string Country = txtcountry.Text;
            string city = txtcity.Text;
            if (IsValid)
            {
                DTOEmployee objdto = new DTOEmployee();
                BLLEmployee objbll = new BLLEmployee();
                objdto.EmpAddress = address;
                objdto.EmpCity = city;
                objdto.EmpContactNo = contactNo;
                objdto.EmpCountry = Country;
                
                objdto.EmpFirstName = firstName;
                objdto.EmpLastName = lastname;
                objdto.EmpNo = empNo;
                objdto.EmpPassword = password;
            
                objdto.EmpState = state;
                objdto.EmpUserName = userName;
         

                int i = objbll.updateEmployee(objdto);
              

                if (i > 0)
                {
                    message("alert('Update Successfull');");

                }


            }
        }
    }
}